// index.js
const app = getApp()
Page({
  data: {
    _data: []
  },
  onLoad(options) {
    // 如果已经获取到，则直接使用
    // 如果还未请求到数据，则创建一个回调函数，等待数据获取完成后调用
    if(app.globalData.musicList){
		  this.dealMusicData()
    } else {
      app.musicCallback = res => {
        this.dealMusicData()
      }
    }
  },
  bindClickMusic (event) {
    const info = event.currentTarget.dataset.item;
    const pId = event.currentTarget.dataset.pid;
    wx.setStorage({
      key: 'g_cabin',
      data: {
        pId,
        id: info.guid
      },
      success ()  {
        wx.switchTab({
          url: `/pages/cabin/index`
        })
      }
    })
  },
  dealMusicData () {
    let _data = app.globalData.musicList;
    this.setData({
      _data
    })
  }
})
